package mysql

import (
	"mxshop_srvs/userop_srv/model"
	proto "mxshop_srvs/userop_srv/proto/gen/v1"
)

func (g *Gorm) GetMessages(req *proto.MessageListRequest) ([]model.LeavingMessages, error) {
	messages := make([]model.LeavingMessages, 0, 8)
	err := g.db.Where(&model.LeavingMessages{
		UserID: req.UserId,
	}).Find(&messages).Error

	return messages, err
}

func (g *Gorm) CreateMessage(req *proto.Message) (uint, error) {
	var msg = model.LeavingMessages{
		UserID:      req.UserId,
		MessageType: model.MsgType(req.MessageType),
		Subject:     req.Subject,
		File:        req.File,
		Message:     req.Message,
	}
	err := g.db.Create(&msg).Error
	return msg.ID, err
}
